curSelectObj = null;

function SetOnFocusToHideSelect()
{
	var obj;
	var i;
	if (document.all){
		document.body.onfocus = TryHideSelect;
		obj = document.all.tags("TABLE");
		for (i=0;i<obj.length;i++){
			obj.item(i).onfocus = TryHideSelect;
		}
		obj = document.all.tags("TD");
		for (i=0;i<obj.length;i++){
			obj.item(i).onfocus = TryHideSelect;
		}
		obj = document.all.tags("A");
		for (i=0;i<obj.length;i++){
			obj.item(i).onfocus = TryHideSelect;
		}
	}
}



function TSelectObject(formVarH,formVarV,idOn,idOff,selectedIndex,nItems)
{
	this.formVarH = formVarH;
	this.formVarV = formVarV;
	this.idOn = idOn;
	this.idOff = idOff;
	this.selectedIndex = selectedIndex;
	this.visible = false;
	this.nItems = nItems;
	return this;
}

function ToggleSelect(selobj)
{
	if(selobj.nItems==0){//当选项为0时返回
		alert("请先设置");
		return;
	}
	//下拉列表中被选中的选项的序号
	var listn=document.all.POManager_SaveForm.types.options.selectedIndex
	var prefixid =listn;
	//idminDatabase为此选项在xml中的id
	var IdinDatabase =document.all.POManager_SaveForm.types.options[listn].value ;
	//在此函数中调用OptionClicked方法，实现页面上select的onchange功能
	OptionClicked(selobj,prefixid,IdinDatabase);
}

function OptionClicked(selobj,idx,val)
{   //删除此句
	//var obj = document.all[selobj.idOn+"_"+idx];
	//原程序中取出vstr为了给显示的层重新赋值
	var vstr = document.all.POManager_SaveForm.types.options[idx].text;
	//alert(vstr);
	vstr = vstr.replace(/^( )+/,"");
	var formObj=null;

	formObj = FindFormByVarName(selobj.formVarH);
	SetFormChanged(formObj);
	if (formObj!=null){
		//eval("formObj."+selobj.formVarV+".value = vstr;");
		eval("formObj."+selobj.formVarH+".value = '"+val+"';");
	}
	selobj.selectedIndex = idx;
	
}

function CalcSelectPosition(selobj)
{
	if (document.all){
		var obj = document.all[selobj.idOff];
		var left = 0;
		var top = 0;
		for (; obj!=document.body; obj=obj.offsetParent){
			left += obj.offsetLeft;
			top  += obj.offsetTop;
		}
		obj = document.all[selobj.idOn].style;
		obj.pixelLeft = left;
		obj.pixelTop = top+document.all[selobj.idOff].offsetHeight+1;
		obj.pixelWidth = document.all[selobj.idOff].offsetWidth;
		if (selobj.nItems<=10){
			obj.pixelHeight = selobj.nItems*16+2;
			obj.overflow = "visible";
		}
		else{
			obj.pixelHeight = 10*16+2;
			obj.overflow = "auto";
		}
	}
}

function PreShowSelect(selobj)
{
	obj = document.all[selobj.idOn].style;
	obj.overflow = "hidden";
}

function ShowSelect(selobj)
{
	if (document.all){
		
		if (curSelectObj!=null)
			HideSelect(curSelectObj);
		selobj.visible = true;
		
		document.all[selobj.idOn].style.visibility="visible";		
		//alert("third");
		CalcSelectPosition(selobj);
		//alert("one");
		//alert(selobj.selectedIndex);
		HighlightOption(selobj,selobj.selectedIndex);
		//alert("two");
		curSelectObj = selobj;
	}
}

function HideSelect(selobj)
{
	if (document.all){
		//alert("1");
		obj = document.all[selobj.idOn].style;
		//alert("2");
		obj.visibility="hidden";
		selobj.visible = false;
		curSelectObj = null;
	}
}

function DelayHideSelect(objname)
{
	setTimeout("HideSelect("+objname+");",200);
}

function TryHideSelect()
{
	if (curSelectObj!=null)
		HideSelect(curSelectObj);
}
tmp_select_vname="type1";
function GenSelItem(num,k,v)
{
	var sobj = "selobj_"+tmp_select_vname;
	var id = "selon_"+tmp_select_vname;
 	document.write("<option ID=\""+id+"_"+num+"\" value=\""+k+"\">"+v+"</Option>");
}
function GenSelItem1(num,k,v)
{
	var sobj = "selobj_"+tmp_select_vname;
	var id = "selon_"+tmp_select_vname;
 	return "<DIV CLASS=\"selectItem\" ID=\""+id+"_"+num+"\" ONCLICK=\"OptionClicked("+sobj+","+num+",'"+k+"');\" ONMOUSEOVER=\"HighlightOption("+sobj+","+num+");\" ONMOUSEOUT=\"NormalOption("+sobj+","+num+");\">"+v+"</DIV>";
}

function FindFormByVarName(vname)
{
	for (i=0;i<document.forms.length;i++){
		if (document.forms[i].elements[vname]!=null)
			return document.forms[i];
	}
	return null;
}



function SetFormChanged(formObj)
{
	if (formObj==null)
		return;
	if (typeof(formObj.tuiFormChanged)=="undefined")
		return;
	formObj.tuiFormChanged.value = 1;
}

//-----add by linhai----------------------------------------------//
function fnSubmit(form)
{
	 
//innerHTML  不包括标签自身  
//outerHTML  包括标签自已
//decodeURI 方法返回一个字符串值。
//encodeURI 方法返回一个编码的 URI。如果您将编码结果传递给 decodeURI，那么将返回初始的字符串。
//encodeURI 方法不会对下列字符进行编码：":"、"/"、";" 和 "?"。

	
	//strTemp="<onload=\"this.outerHTML=decodeURI(\'"+encodeURI(emailstyleform.innerHTML)+"\');\">";
	strTemp1=encodeURI(emailstyleform.innerHTML);
	//strTemp=strTemp1.outerHTML;
	//alert(strTemp1);
	strTemp=decodeURI(strTemp1);
	//alert(strTemp);
	
	form.tHtml.value=strTemp;
	//alert(submitform.TransmitEmail_tHtml.value);
	form.submit();
}